package com.hxx.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hxx.domain.Person;
import com.hxx.service.PersonService;
import com.hxx.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class PersonController {
    @Autowired
    private PersonService personService;


    @PostMapping("/showPage")
    public R showPage(@RequestBody Page<Person> page){
        personService.showPage(page);
        return R.ok().data("list",page.getRecords())
                .data("total",page.getTotal());
    }
    /**
     * 显示数据
     */
    @GetMapping("/show")
    public R show(){
        return R.ok().data("list",personService.list());
    }

    /**
     * 添加数据
     */
    @PostMapping("/add")
    public R add(@RequestBody Person person){
        personService.save(person);
        return R.ok();
    }

    /**
     * 修改数据
     */
    @PutMapping("/update")
    public R update(@RequestBody Person person){
        personService.updateById(person);
        return R.ok();
    }

    /**
     * 删除数据
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable Long id){
        personService.removeById(id);
        return R.ok();
    }
}



































